<template>
    <div class="page-order-detail">
        <div class="status">
            <strong class="text">{{detail.orderState | filterOrderStatus}}</strong>
            <p class="tip" >{{orderStatusText[detail.orderState]}}</p>
            <div class="handle-button">
                <van-button v-if="detail.orderState == 1" plain class="action" @click="cancel(detail.orderId)">取消订单</van-button>
                <van-button v-if="detail.orderState == 2" plain class="action" @click="concactOther">联系其他设计师</van-button>
                <a v-if="detail.orderState == 3 && mobile" class="call-link" :href="`tel:${mobile}`">拨打电话给TA</a>
                 <van-button 
                    v-if="detail.orderState == 3" 
                    plain 
                    class="action" 
                    @click="onConfirm">已沟通</van-button>
                <van-button 
                    v-if="detail.orderState == 6" 
                    plain 
                    class="action" 
                    @click="goComment(detail.orderId)">评价TA</van-button>
            </div>
        </div>

        <ul class="order-list">
            <li class="order-item">
                <div class="hd van-hairline--bottom">
                    订单编号：{{detail.demandId}}
                    <span class="status">{{detail.orderState | filterOrderStatus}}</span>
                </div>
                <div class="bd">
                    <div class="img">
                        <img v-lazy="detail.designerHead" alt="">
                    </div>
                    <div class="txt">
                        <div class="name">
                            需求方 - {{detail.designerName}}
                            <time>{{detail.createTime}}</time>
                        </div>
                        <div class="desc">
                            复古、极客、艺术公寓
                        </div>
                    </div>
                </div>
                <div class="ft">
                    诚意金：<strong class="price">￥{{detail.earnestMoney}}</strong>
                </div>
            </li>
        </ul>
    </div>
</template>

<script>
import { demandUpdate, bindAxB, cusOrderInfo } from '../../api/demand'
export default {
    name: 'orderDetail',
    props: {
        id: String
    },
    data(){
        return {
            detail: {},
            orderStatusText: {
                1: '您已成功发起，请耐心等待', //待接单 button-取消预约
                2: '原因：最近比较忙', //未接单
                3: '', //已接单 button-拨打电话给TA
                4: '', //已沟通 button-评价TA
                5: '', //评价 button-评价TA
                6: '', //已完成
                7: '', //已过期
                8: '', //已取消
            },
            mobile: '',
        }
    },
    methods: {
        cancel(orderId){
            demandUpdate({
                orderId,
                handleType: 'CANCEL'
            }).then(rsp => {
                if(rsp.code === 200){
                    this.$toast.success('取消成功')
                    this.$router.replace({name: 'hireOrder'})
                }
            })
        },

        onConfirm(){
            //已沟通
            demandUpdate({
                orderId: this.detail.orderId,
                handleType: 'CONFIRM'
            }).then(rsp => {
                if(rsp.code === 200){
                    this.$toast.success('操作成功')
                    this.$router.replace({name: 'hireOrder'})
                }
            })
        },

        callTa(){
            bindAxB({
                flag: 1,
                designerId: this.detail.designerId,
                orderId: this.detail.orderId
            }).then(rsp => {
                if(rsp.code === 200 && rsp.data && rsp.data && rsp.data !== 'FAIL'){
                    this.mobile = rsp.data.split(',')[1]
                }
            })
        },

        goComment(orderId){
            this.$router.push({name: 'orderComment', params: {orderId}})
        },

        concactOther(){
            this.$router.push({name: 'hireFind'})
        },

        getOrderDetail(){
          cusOrderInfo(this.id).then(rsp => {
            if(rsp.code === 200){
               this.detail = rsp.data
               if(this.detail.orderState == 3){
                    this.callTa()
                }
            }
          })
        }
    },
    created(){
        this.getOrderDetail()
    }
}
</script>

<style lang="less">
.page-order-detail{
    & > .status{
        padding: 50px 0;
        text-align: center;
        background-color: #fff;
        .text{
            display: block;
            margin: 0 auto 15px;
            font-size: 120%;
        }
        .tip{
            font-size: 13px;
            color: #555;
        }
        .handle-button{
            margin-top: 20px;
            .call-link{
                position: relative;
                margin-right: 10px;
                padding: 0 10px;
                display: inline-block;
                height: 44px;
                line-height: 42px;
                border-radius: 2px;
                box-sizing: border-box;
                font-size: 16px;
                text-align: center;
                border: 1px solid #eee;
                border-radius: 5px;
                text-decoration: none;
            }
        }
    }

    .order-list{
        .order-item{
            padding: 0 10px 10px;
            margin: 10px auto;
            background-color: #fff;
            .hd{
                line-height: 40px;
                font-size: 12px;
                .status{
                    float: right;
                }
            }
            .bd{
                display: flex;
                align-items: center;
                padding: 10px 0;
                .img{
                    width: 60px;
                    height: 60px;
                    margin-right: 10px;
                    border-radius: 50%;
                    overflow: hidden;
                }
                .txt{
                    flex: 1;
                    min-width: 0;
                    .name{
                        line-height: 30px;
                        time{
                            float: right;
                            font-size: 12px;
                            color: #707070;
                        }
                    }
                    .desc{
                        font-size: 14px;
                        color: #707070;
                        line-height: 1.75;
                    }
                }
            }
            .ft{
                margin-top: 5px;
                text-align: right;
                font-size: 14px;
                color: #707070;
                .price{
                    font-size: 140%;
                    color: #212121;
                }
            }
        }
    }
}
</style>
